package com.suixinsanren.design.iterator.demo03;

import java.awt.*;

public class DinerMenu {

    private static final int MAX_ITEMS = 6;
    private int numberOfItems = 0;
    private MenuItem[] menuItems;

    public DinerMenu() {
        this.menuItems = new MenuItem[MAX_ITEMS];
        addItem("素食主义者", "全麦生菜西红柿培根", true, 2.99);
        addItem("三明治", "生菜西红柿培根配全麦", false, 2.99);
        addItem("当天特供汤", "今天的汤，配上一份土豆沙拉", true, 3.29);
        addItem("热狗", "一份热狗，有泡菜、调味品、洋葱，上面加奶酪", true, 3.05);
    }

    private void addItem(String name, String description, boolean vegetarian, double price) {
        if (numberOfItems >= MAX_ITEMS) {
            System.out.println("对不起，菜单都满了！无法将项目添加到菜单");
        } else {
            menuItems[numberOfItems++] = new MenuItem(name, description, vegetarian, price);
        }
    }

    public MenuItem[] getMenuItems() {
        return this.menuItems;
    }

    public Iterator<MenuItem> iterator() {
        return new DinerMenuIterator(this);
    }
}
